﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class template : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Login();
    }
    NguoiDung nd = new NguoiDung();
    private void Login()
    {
        if(Session["username"] != null && Session["password"] != null)
        {
                Login1.Visible = false;
                lb_dangnhap.Visible = true;
                lbt_dangxuat.Visible = true;


                lb_dangnhap.Text = "Chào " + Session["name"].ToString() + ", ";
        }
    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
       
        if(nd.CheckUser(Login1.UserName,Login1.Password)==true)
        {
            Login1.Visible = false;
            lb_dangnhap.Visible = true;
            lbt_dangxuat.Visible = true;            

            Session["name"]=nd.GetName(Login1.UserName);
            lb_dangnhap.Text = "Chào " + Session["name"].ToString()+ ", ";

            Session["username"] = Login1.UserName;
            Session["password"] = Login1.Password;
            Response.Redirect(Request.RawUrl);

        }
    }
   
  
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Login1.Visible = true;
        lb_dangnhap.Visible = false;
        lbt_dangxuat.Visible = false;

        Session["username"] = null;
        Session["password"] = null;

        Response.Redirect("default.aspx");
    }
}
